package com.example.demo1;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

public class CakeDB {
    private static Map<String,Cake> cakeMap = new LinkedHashMap<String, com.example.demo1.Cake>();
    static{
        cakeMap.put("1",new Cake("1","A类蛋糕",52,78));
        cakeMap.put("2",new Cake("2","B类蛋糕",23,17));
        cakeMap.put("3",new Cake("3","C类蛋糕",34,15));
        cakeMap.put("4",new Cake("4","D类蛋糕",86,46));
        cakeMap.put("5",new Cake("5","E类蛋糕",46,26));
    }
    public static void updateStock(String id, int count) {
        Cake cake = cakeMap.get(id);
        if (cake != null) {
            cake.reduceStock(count);
        } else {
            throw new IllegalArgumentException("蛋糕ID不存在");
        }
    }

    public static int getStock(String id) {
        Cake cake = cakeMap.get(id);
        if (cake != null) {
            return cake.getStock();
        } else {
            return 0;
        }
    }
    //获得所有的蛋糕
    public static Collection<Cake> getAll(){

        return (Collection<Cake>) cakeMap.values();
    }
    //根据id指定的获取蛋糕
    public static Cake getCake(String id){

        return cakeMap.get(id);

    }
}
